package excise03;


class PrintNumber extends Thread{

    public PrintNumber(){

    }
    public PrintNumber(String name){
        super(name);
    }
    @Override
    public void run() {

        /*try{
            Thread.sleep(1000);
        }catch(InterruptedException e){
            e.printStackTrace();
        }*/

        for(int i=1;i<=100;i++){
            if(i % 2 == 0){
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }

            if(i % 20 == 0){
                Thread.yield(); //将当前线程从运行状态转换为就绪状态，以便给其他线程更多的机会来执行
            }
        }
    }
}

public class EvenNumberTest {
    public static void main(String[] args) {

        PrintNumber test1 = new PrintNumber("线程1");
        test1.setName("子线程1");
        test1.start();

        Thread.currentThread().setName("主线程");

        for(int i=1;i<=100;i++){
            if(i % 2 == 0){
                System.out.println(Thread.currentThread().getName() + ":" + i + "****");
            }
        }
    }
}

